﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using  System.Globalization; 

namespace GPCSC.Web.WBWZ
{
    public partial class index : PageBase
    {
        public System.Text.StringBuilder innerHTML = new System.Text.StringBuilder();
        public System.Text.StringBuilder mqri = new System.Text.StringBuilder();

        protected void Page_Load(object sender, EventArgs e)
        {

            buildImage();
            buildGTXW();
            buildTZGG();
            buildGZJB();
            buildJYJL();
            buildDYBG();
            buildMQRJ();
            this.Label1.Text = DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day + "日";
          //  DateTime ti = DateTime.Now;
            //this.Label2.Text =    LunarDay.GetLunarCalendar(ti);
        }

        protected void buildMQRJ()
        {
            Hashtable htable = new Hashtable();

            DataSet ds = new DataReturn().ReturnData(htable, "sel_mq_all");
            if (ds != null)
            {
                mqri.Append("<td width=\"372\" valign=\"top\">");
                mqri.Append("<table width=\"364\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    if (i < 4)
                    {
                        mqri.Append("<tr><td class=\"text\">");
                        mqri.Append("<a  href=\"newsList.aspx?newsid=" + ds.Tables[0].Rows[i]["tabids"].ToString() + "&value=6\" >");
                       // mqri.Append( ds.Tables[0].Rows[i]["mqdate"].ToString() + " " + ds.Tables[0].Rows[i]["lgname"].ToString() + "民情日记");
                        mqri.Append(ds.Tables[0].Rows[i]["mqtitle"].ToString());
                        mqri.Append("</a>");
                         mqri.Append("</td>");
                         mqri.Append("</tr>");
                    }
                     else if (i == 4)
                    {
                        mqri.Append("<tr><td class=\"text\">");
                        mqri.Append("<a  href=\"newsList.aspx?newsid=" + ds.Tables[0].Rows[i]["tabids"].ToString() + "&value=6\" >");
                        //mqri.Append(ds.Tables[0].Rows[i]["mqdate"].ToString() + " " + ds.Tables[0].Rows[i]["lgname"].ToString() + "民情日记");
                        mqri.Append(ds.Tables[0].Rows[i]["mqtitle"].ToString());
                        mqri.Append("</a>");
                        mqri.Append("</td>");
                        mqri.Append("</tr>");
                        mqri.Append("</table></td>");
                        mqri.Append("<td width=\"6\"></td>");
                        mqri.Append("<td width=\"372\" valign=\"top\"><table width=\"364\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");

                    }
                    else
                    {
                        mqri.Append("<tr><td class=\"text\">");
                        mqri.Append("<a  href=\"newsList.aspx?newsid=" + ds.Tables[0].Rows[i]["tabids"].ToString() + "&value=6\" >");
                        //mqri.Append(ds.Tables[0].Rows[i]["mqdate"].ToString() + " " + ds.Tables[0].Rows[i]["lgname"].ToString() + "民情日记");
                        mqri.Append(ds.Tables[0].Rows[i]["mqtitle"].ToString());
                        mqri.Append("</a>");
                        mqri.Append("</td>");
                        mqri.Append("</tr>");
                    }
                }
                mqri.Append("</table>");
                mqri.Append("</td>");
            }
        }

        // 绑定首页的新闻图片
        protected void buildImage()
        {
            Hashtable htable = new Hashtable();
           
            DataSet ds = new DataReturn().ReturnData(htable, "sel_Isimage_all");
            if (ds != null)
            {
                Repeater1.DataSource = ds;
                Repeater1.DataBind();
            }
            
        }


        //绑定动态新闻
        protected void buildGTXW()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "2");
            DataSet ds = new DataReturn().ReturnData(htable,"sel_sydtxw_all");
            if (ds != null)
            {

                GZDT.DataSource = cutTitle(ds);
                GZDT.DataBind();
            }
        }

        //绑定通知公告
        protected void buildTZGG()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "1");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            if (ds != null)
            {

                tzgg.DataSource = cutTitles(ds);
                tzgg.DataBind();
                int j = 0;
                if (ds.Tables[0].Rows.Count >= 5)
                {
                    j = 5;
                }
                else
                {
                    j = ds.Tables[0].Rows.Count;
                }
                for (int i = 0; i < j; i++)
                {
                    innerHTML.Append("<a href='newsList.aspx?newsid=" + ds.Tables[0].Rows[i]["NewsID"].ToString() + "'>" + ds.Tables[0].Rows[i]["NewsTitles"].ToString().Replace("^", "\n") + "</a>&nbsp;&nbsp;&nbsp;&nbsp;");
                }
            }
        }

        
       //绑定工作简报
        protected void buildGZJB()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "5");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            if (ds != null)
            {

                gzjb.DataSource = cutTitle(ds);
                gzjb.DataBind();
            }
        }

        

        //绑定经验交流
        protected void buildJYJL()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "3");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            if (ds != null)
            {

                jyjl.DataSource = cutTitle(ds);
                jyjl.DataBind();
            }
        }



        //绑定调研报告
        protected void buildDYBG()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "4");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            if (ds != null)
            {

                dybg.DataSource = cutTitle(ds);
                dybg.DataBind();
            }
        }
        
        /// <summary>
        /// 若标题过长  截取标题
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        protected DataSet cutTitle(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["NewsTitles"].ToString().Length > 24)
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString().Substring(0, 24) + "...";
                    }
                    else
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString();
                    }
                }
            }
            return ds;
        }
        protected DataSet cutTitles(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["NewsTitles"].ToString().Length > 18)
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString().Substring(0, 18) + "...";
                    }
                    else
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString();
                    }
                }
            }
            return ds;
        }
    }
}